function ubb2html(f) {
    function o(h) {
        return h != null && h != "" ? !isNaN(h) : false
    }
    var b = String(f),p = [],n = 0;
    b = b.replace(/\r?\n/g, "<br />");
    b = b.replace(/\[code\s*(?:=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,
    function(h) {
        n++;
        p[n] = h;
        return "[\tubbcodeplace_" + n + "\t]"
    });
    for (f = 1; f <= n; f++) b = b.replace("[\tubbcodeplace_" + f + "\t]", p[f]);
    return b = b.replace(/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/ig,
    function(h, i, a) {
        return i + a.replace(/[\t ]/g,
        function(k) {
            return {
                "\t": "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                " ": "&nbsp;"
            } [k]
        })
    })
}
function html2ubb(f) {
	function o(g) {
        var c;
        if (c = g.match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)) {
            for (g = (c[1] * 65536 + c[2] * 256 + c[3] * 1).toString(16); g.length < 6;) g = "0" + g;
            g = "#" + g
        }
        return g = g.replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i, "#$1$1$2$2$3$3")
    }
	a = String(f),k = [],m = 0;
    a = a.replace(/<br\s*?\/?>/ig, "\r\n");
    a = a.replace(/\[code\s*(=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,
    function(g) {
        m++;
        k[m] = g;
        return "[\tubbcodeplace_" + m + "\t]"
    });
    a = a.replace(/((\s|&nbsp;)*\r?\n){3,}/g, "\r\n\r\n");
    a = a.replace(/^((\s|&nbsp;)*\r?\n)+/g, "");
    a = a.replace(/((\s|&nbsp;)*\r?\n)+$/g, "");
    for (f = 1; f <= m; f++) a = a.replace("[\tubbcodeplace_" + f + "\t]", k[f]);
    return a.replace(/&nbsp;/ig, " ");
};